#include <iostream>
#include<cmath>
using namespace std;

typedef unsigned long long LL;
const int N = 1e6 + 10; 
LL p[N], c, n;

void push(LL x)
{
    p[++c] = x;
} 

void pop()
{
	c--;
}
int main()
{
	int t;
	cin >> t;
	while(t--)
	{
		c = 0;
		cin >> n;
		while(n--)
		{
			string s;
			LL x;
			cin >> s;
			if(s == "push")
			{
				cin >> x;
				push(x);
			}
			else if(s == "pop")
			{
				if(c)
				{
					pop();
				}
				else
				    cout << "Empty" << endl;
			}
			else if(s == "query")
			{
				if(c)
				{
					cout << p[c] << endl;
				}
				else
				    cout << "Anguei!" << endl;
			}
			else
			    cout << c << endl; 
		}
	}
	return 0;
}
